home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASROTO.ZIP / ROTOEXAM.CPP < prev    next >
C/C++ Source or Header  |  1996-05-23  |  3KB  |  92 lines

  1. // rotozoomer example.
  2.  
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <math.h>
  6. #include <stdlib.h>
  7. #include "roto.h"
  8. #include "timer.h"
  9.  
  10. void vidmode(short);
  11. #pragma aux vidmode parm [ax] = "int 10h"
  12.  
  13. void main()
  14. {
  15.   unsigned char *mapptr=new unsigned char [0x20000];
  16.   unsigned char *map=(unsigned char*)(((unsigned long)mapptr+0xFFFF)&~0xFFFF);
  17. // map is segment aligned.
  18.  
  19.   int i,j;
  20.  
  21.   for (i=0; i<256; i++)   // simple xor pattern
  22.     for (j=0; j<256; j++)
  23.       map[i*256+j]=i^j;
  24.   for (i=0; i<256; i++)   // thin vertical line
  25.     map[i*256]=(i&1)?0:255;
  26.   for (i=0; i<256; i++)   // thick horizontal line
  27.     for (j=0; j<4; j++)
  28.       map[i+j*256]=((i^j)&1)?0:255;
  29.   for (i=0; i<16; i++)    // mark texture origin
  30.     for (j=0; j<16; j++)
  31.       map[i*256+j]=((i^j)&1)?0:255;
  32.  
  33.   vidmode(0x13);
  34.   outp(0x3c8, 0);  // grey palette
  35.   for (i=0; i<64; i++)
  36.     for (j=0; j<12; j++)
  37.       outp(0x3c9,i);
  38.  
  39.   tmInit();
  40.  
  41.   unsigned long starttime=tmGetTimer();
  42.   int frame=0;
  43.   while (!kbhit())
  44.   {
  45.     double frametime=tmGetTimer()*0.00005; // some values
  46.     double xmid=160+sin(frametime*0.0067521345+0.1)*90;
  47.     double ymid=100+sin(frametime*0.00912348976+0.5)*90;
  48.     double txmid=128+sin(frametime*0.000913784+1.02434)*64;
  49.     double tymid=128+sin(-frametime*0.0012821345+2.1944)*64;
  50.     double zoom=exp(sin(frametime*0.00398175)*0.8-0.5);
  51.     double angle=frametime*0.012345897;
  52.  
  53.     long zoomx=65536/1.2*zoom*cos(angle); // transformation matrix calculation
  54.     long zoomy=65536/1.2*zoom*sin(angle);
  55.     long zoomxd=-65536*zoom*sin(angle);
  56.     long zoomyd=65536*zoom*cos(angle);
  57.     long curx=txmid-xmid*zoomx-ymid*zoomxd;
  58.     long cury=tymid-xmid*zoomy-ymid*zoomyd;
  59.  
  60.     while (inp(0x3da)&8);    // wait for retrace, comment to get
  61.     while (!(inp(0x3da)&8)); // maximum framerate as a benchmark.
  62.     outp(0x3c8,0); // show frametime needed
  63.     outp(0x3c9,63);
  64.     outp(0x3c9,0);
  65.     outp(0x3c9,0);
  66.     texturescreen((unsigned char*)0xA0000, map, curx, cury, zoomx, zoomy, zoomxd, zoomyd, 40, 25, 320, ROTO_MOV, abs(zoomx)<abs(zoomy));
  67.     outp(0x3c8,0);
  68.     outp(0x3c9,0);
  69.     outp(0x3c9,0);
  70.     outp(0x3c9,0);
  71.  
  72.     frame++;
  73.   }
  74.  
  75.   unsigned long endtime=tmGetTimer();
  76.  
  77.   tmClose();
  78.  
  79.   while (kbhit()) // flush
  80.     getch();
  81.   vidmode(3);
  82.   vidmode(3);
  83.  
  84.   char buf[30];
  85.   ultoa(frame*11930460.0/(endtime-starttime), buf, 10);
  86.   buf[strlen(buf)+1]=0;
  87.   buf[strlen(buf)]=buf[strlen(buf)-1];
  88.   buf[strlen(buf)-2]='.';
  89.   strcat(buf, " fps\r\n");
  90.   cputs(buf);
  91. }
  92.